<!DOCTYPE html>
<html lang="zh-CN">
    <head>
  <!-- 元数据 -->
  <meta charset="utf-8">
  <link rel="icon" href="">
  <title>C++ primary（上部） | ALgarth's blog</title>
  <meta name="author" content="ALgarth" />
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="robots" content="index,follow" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <meta name="format-detection" content="telphone=no, email=no" />
  
    <meta name="keywords" content="c++从入门到不入门" />
  
  <meta name="description" content="本篇博客为的是复习一遍C++的基础知识，方便从C语言更快的转型为C++语言 本文只是快速的提供模板和粗略的将部分代码一笔带过 前言中当然要感谢柳婼姐和CSDN的c++相关资料， 那么，我们进入正题： C语言向C++的进阶本文打算按照以下顺序进行讲解  1.C++ 语言的优势 2.初步的C++用法介绍 3.板子的提出 4.依据板子进行其他的讲解 5.板子中其他头文件的用法说明 6.其他不在板子内的常">
<meta property="og:type" content="article">
<meta property="og:title" content="C++ primary（上部）">
<meta property="og:url" content="http://algarth.github.io/2020/10/11/C-primary/index.html">
<meta property="og:site_name" content="ALgarth&#39;s blog">
<meta property="og:description" content="本篇博客为的是复习一遍C++的基础知识，方便从C语言更快的转型为C++语言 本文只是快速的提供模板和粗略的将部分代码一笔带过 前言中当然要感谢柳婼姐和CSDN的c++相关资料， 那么，我们进入正题： C语言向C++的进阶本文打算按照以下顺序进行讲解  1.C++ 语言的优势 2.初步的C++用法介绍 3.板子的提出 4.依据板子进行其他的讲解 5.板子中其他头文件的用法说明 6.其他不在板子内的常">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://algarth.github.io/null">
<meta property="article:published_time" content="2020-10-11T03:12:55.000Z">
<meta property="article:modified_time" content="2020-10-31T02:37:45.566Z">
<meta property="article:author" content="ALgarth">
<meta property="article:tag" content="c++从入门到不入门">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://algarth.github.io/null">
<meta name="twitter:site" content="@null">
  
  <!-- 站点验证相关 -->
  
    
    
    
  
  <!-- 样式表文件 -->
  <link rel="stylesheet" id="kratos-css" href="/css/kratosr.min.css" type="text/css" media="all">
  <link rel="stylesheet" id="highlight-css" href="/css/highlight.min.css" type="text/css" media="all">
  <link rel="stylesheet" id="fontawe-css" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" type="text/css" media="all">
  <link rel="stylesheet" id="nprogress-css" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" type="text/css" media="all">
  
  
  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css">
  
  
    <link rel="stylesheet" id="darkmode-css" href="/css/kr-dark.min.css" type="text/css" media="all">
  
  <!-- 不得不预先加载的一些JS文件 -->
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
  
    <script src="https://cdn.jsdelivr.net/npm/qrcode_js@1.0.0/qrcode.min.js"></script>
  
  
<meta name="generator" content="Hexo 5.2.0"><link rel="alternate" href="/atom.xml" title="ALgarth's blog" type="application/atom+xml">
</head>


    <body class="custom-background">
        <div id="kratos-wrapper">
    <div id="kratos-page">
        <div id="kratos-header">
            <div class="nav-toggle"><a class="kratos-nav-toggle js-kratos-nav-toggle"><i></i></a></div>
            <header id="kratos-header-section">
                <div class="container">
                    <div class="nav-header">
                        <div class="color-logo"><a href="/">ALgarth&#39;s blog</a></div>
                        <nav id="kratos-menu-wrap">
                            <ul id="kratos-primary-menu" class="sf-menu">
                                
                                    
                                        <li><a href="/"><i class="fa fa-home"></i>首页</a></li>
                                    
                                
                                    
                                        <li><a href="/archives/"><i class="fa fa-file"></i>档案馆</a></li>
                                    
                                
                                    
                                        <li>
                                            <a><i class="fa fa-link"></i>链接</a>
                                            <ul class="sub-menu">
                                                
                                                    
                                                
                                                    
                                                        <li><a target="_blank" rel="noopener" href="https://blog.csdn.net/algarth">作者博客</a></li>
                                                    
                                                
                                                    
                                                        <li><a target="_blank" rel="noopener" href="https://github.com/ALgarth">项目链接</a></li>
                                                    
                                                
                                            </ul>
                                        </li>
                                    
                                
                            </ul>
                        </nav>
                    </div>
                </div>
            </header>
        </div>
        <div class="kratos-start kratos-hero-2">
            <!-- <div class="kratos-overlay"></div> -->
            <div class="kratos-cover kratos-cover-2 text-center">
                <div class="desc desc2 animate-box">
                    <a href="/">
                        <h2>ALgarth&#39;s blog</h2> <br />
                        <span>欢迎捞到摸鱼仙人的博客呢_(:3」∠)_</span>
                    </a>
                </div>
            </div>
        </div>

        <div id="kratos-blog-post">
            <div class="container">
                <div class="row">
                    
        <div id="main">
            <section class="col-md-8">
    <article>
        <div class="kratos-hentry kratos-post-inner clearfix">
            <header class="kratos-entry-header">
                <h1 class="kratos-entry-title text-center">C++ primary（上部）</h1>
                
                <div class="kratos-post-meta text-center">
                    <span>
                        <i class="fa fa-calendar"></i> 2020-10-11
                        <i class="fa fa-folder"></i> 分类于 
                        <i class="fa fa-user"></i> 作者 ALgarth
                        <i class="fa fa-edit"></i> 
                        
                        
                            ~5.51K
                        
                        字
                        
                    </span>
                </div>
            </header>
            <div class="kratos-post-content">
                
                    <div class="kratos-post-inner-toc">
                        <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#C%E8%AF%AD%E8%A8%80%E5%90%91C-%E7%9A%84%E8%BF%9B%E9%98%B6"><span class="toc-number">1.</span> <span class="toc-text">C语言向C++的进阶</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80-C-%E8%AF%AD%E8%A8%80%E7%9A%84%E4%BC%98%E5%8A%BF"><span class="toc-number">1.1.</span> <span class="toc-text">一. C++语言的优势</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C-%E5%88%9D%E6%AD%A5%E7%9A%84C-%E8%AF%AD%E6%B3%95%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.2.</span> <span class="toc-text">二. 初步的C++语法介绍</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#iostream"><span class="toc-number">1.2.1.</span> <span class="toc-text">iostream</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#namespace"><span class="toc-number">1.2.2.</span> <span class="toc-text">namespace</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cin%EF%BC%8Ccout"><span class="toc-number">1.2.3.</span> <span class="toc-text">cin，cout</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#endl"><span class="toc-number">1.2.4.</span> <span class="toc-text">endl</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89-%E6%9D%BF%E5%AD%90%E7%9A%84%E6%8F%90%E5%87%BA"><span class="toc-number">1.3.</span> <span class="toc-text">三. 板子的提出</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#bits-stdc"><span class="toc-number">1.3.1.</span> <span class="toc-text">bits&#x2F;stdc++</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#define"><span class="toc-number">1.3.2.</span> <span class="toc-text">define</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ios-sync-with-stdio-0"><span class="toc-number">1.3.3.</span> <span class="toc-text">ios::sync_with_stdio(0)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B2%A1%E6%9C%89%E6%8F%90%E5%88%B0%E7%9A%84O2%E5%8A%A0%E9%80%9F"><span class="toc-number">1.3.4.</span> <span class="toc-text">没有提到的O2加速</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cin-tie-0"><span class="toc-number">1.3.5.</span> <span class="toc-text">cin.tie(0)</span></a></li></ol></li></ol></li></ol>
                    </div>
                
                <hr />
                <p>本篇博客为的是复习一遍C++的基础知识，方便从C语言更快的转型为C++语言</p>
<p>本文只是快速的提供模板和粗略的将部分代码一笔带过</p>
<p>前言中当然要感谢柳婼姐和CSDN的c++相关资料，</p>
<p>那么，我们进入正题：</p>
<h1 id="C语言向C-的进阶"><a href="#C语言向C-的进阶" class="headerlink" title="C语言向C++的进阶"></a>C语言向C++的进阶</h1><p>本文打算按照以下顺序进行讲解</p>
<blockquote>
<p>1.C++ 语言的优势</p>
<p>2.初步的C++用法介绍</p>
<p>3.板子的提出</p>
<p>4.依据板子进行其他的讲解</p>
<p>5.板子中其他头文件的用法说明</p>
<p>6.其他不在板子内的常用函数写法和C++11</p>
</blockquote>
<h2 id="一-C-语言的优势"><a href="#一-C-语言的优势" class="headerlink" title="一. C++语言的优势"></a>一. C++语言的优势</h2><p>作为一个年轻的C++入门学生，我肯定不能介绍C++语言优势介绍的很详细。但是在竞赛中，使用C++语言相对于JAVA语言和C语言的优势我还是略懂一二的</p>
<p>1.<strong>C++语言书写方便</strong>，相对于JAVA来讲没有一般不需要在竞赛中反复写class，而且单看输入输出，节省了java中sysout的用法，同时不需要scanner</p>
<p>2.<strong>C++语言方便C语言学习的同学上手</strong>，C++语言在当初开发的时候就是BS大神考虑增强C语言的能力开发的<em>“带类的C”</em>，C++语言对于C语言是完全兼容的</p>
<p>3.<strong>C++提供了较多的模板（STL）</strong>，对于即使没有学过数据结构的新生来说十分友好，并且节省了大量的代码行数，<del>当然弊端是回头学数据结构的时候就不想打了</del></p>
<h2 id="二-初步的C-语法介绍"><a href="#二-初步的C-语法介绍" class="headerlink" title="二. 初步的C++语法介绍"></a>二. 初步的C++语法介绍</h2><p>首先看一个基本的C++代码</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> n;</span><br><span class="line">	<span class="built_in">cin</span>&gt;&gt;n;</span><br><span class="line">	<span class="built_in">cout</span>&lt;&lt;n&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>学过C语言的同学是不是觉得简单易懂！！</p>
<p>那么先说几点和C语言不同的地方：</p>
<h3 id="iostream"><a href="#iostream" class="headerlink" title="iostream"></a>iostream</h3><p>C语言中需要写入stdio.h头文件，在C++中仍然需要写入头文件，原本C语言中的头文件都是.h(head)格式的文件，在c++中不再使用这样的文件了，取而代之的c++头文件，iostream因为包含了cin，cout还有cerr等新的面向对象语言的输入输出方式，所以不得已取消了stdio的应用，当然，源文件是随着编译器不断变化的，如果你是devc的爱好者，其实devc中iostream内部包含了stdio的全部内容，当然其他编辑器可能并不那么友好，比如VS编译器。</p>
<p>原本的C语言中的头文件比如math.h之类的仍然可以在c++中使用，但是c++提供了更方便的使用方法，只需要去掉扩展名，并在前面加上字母c就可以方便使用了。举个例子</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cmath&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstring&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cctype&gt;</span></span></span><br></pre></td></tr></table></figure>

<p>这些写法分别对应着C语言相应的头文件</p>
<h3 id="namespace"><a href="#namespace" class="headerlink" title="namespace"></a>namespace</h3><p>namespace是为了解决C语言中重复使用相同变量名问题的，比如两份不同学校的代码要拷贝到一起，但是中间有很多变量名是相同的，我们通过namespace指定一个学校名就可以解决问题了，比如两个zs，一个是a学校的zs，一个是b学校的zs，毕业之后就是a::zs和b::zs，这里的双冒号就是c++在指定namespace下属的写法</p>
<p>但是其实很多c++自带的东西都是写在std下的，所以其实在学算法的时候不用深挖，直接每次写上using namespace std就是了，如同H5当中指定base嗷~</p>
<h3 id="cin，cout"><a href="#cin，cout" class="headerlink" title="cin，cout"></a>cin，cout</h3><p>这两个兄弟其实很令人舒服，cin和cout其实真的相当舒服好用，既不用像java和C语言那样指定类型输入，而且写起来还简单，舒服啊</p>
<p>写的时候这个尖括号的理解其实是这样的，尖括号其实是一个运算符，这个运算符在cin的时候形象的理解为将数据输送到括号指向的那个方向，cout的时候指向cout这里，是把数据写入数据流，就可以了</p>
<p>cout的最大弊端是按格式输出内容不如printf，所以如果遇到按格式输出，不要犹豫，直接printf</p>
<p>当然其实在cin，cout中不指定类型让机器判断也是有弊端的，这个下文会提到</p>
<h3 id="endl"><a href="#endl" class="headerlink" title="endl"></a>endl</h3><p>endl就是C语言中的\n，c++仍然可以使用，但是要在字符串中使用，本质上来讲endl确实速度会慢一点，因为有刷新流的事儿，但是不用担心。他最大的优势就是使代码看起来很简介很舒服。</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;hello world&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line"><span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;hello world\n&quot;</span>;</span><br></pre></td></tr></table></figure>

<h2 id="三-板子的提出"><a href="#三-板子的提出" class="headerlink" title="三. 板子的提出"></a>三. 板子的提出</h2><p><del>其实我超级喜欢用板子的</del> </p>
<p>首先板子分为很多种，有时一般把常用的算法称之为板子，但是我这儿的板子单指打代码开始的时候加上的框架</p>
<p>话不多说，上板子！！</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> asd cout&lt;&lt;<span class="meta-string">&quot; SB &quot;</span>&lt;&lt;endl; </span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ll long long </span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ull unsigned long long </span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INF 0x3f3f3f3f </span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">    ios::sync_with_stdio(<span class="number">0</span>);</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;   </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这套板子我始终放在自己的搜狗快速输入栏，实在是相当的好用，当然具体怎么放取决于你的想法，（比如我把define的单独放在一起，其他的放在一起）</p>
<p><del>其实在devc中有一个设置可以在创建文件的时候自动生成框架</del></p>
<p>板子内容先解释一波</p>
<h3 id="bits-stdc"><a href="#bits-stdc" class="headerlink" title="bits/stdc++"></a>bits/stdc++</h3><p>万能头文件，懂得都懂，包含了c++和C语言几乎所有头文件，在VS上可能没有，需要手动添加。有了他，再也不用担心哪一天写头文件写少了！！</p>
<p>这是一种拿编译时间交换执行时间的方法，但反而oj在判题的时候只看执行时间</p>
<p>当然弊端是有些平台不支持，有些比赛也是</p>
<h3 id="define"><a href="#define" class="headerlink" title="define"></a>define</h3><p>这堆define都是相当灵性的定义，中间定义了方便调试的asd，ll快捷写法，和整数无穷大，Ox3f3f3f3f是一个好用的数字，他是1e9左右的数字，但是2倍又不会超过2147483647，所以一般表示无穷大很好用！！</p>
<p>（当然根据罗勇军的说法来看，常量定义的时候最好用const定义而不是的define，防止在打赛的时候出问题）</p>
<h3 id="ios-sync-with-stdio-0"><a href="#ios-sync-with-stdio-0" class="headerlink" title="ios::sync_with_stdio(0)"></a>ios::sync_with_stdio(0)</h3><p>这个是关闭同步流，cin和cout采用的不是一套输入输出，为了兼容性，每次使用cin，cout的时候都会去和scanf和printf进行同步，这项操作使得cin，cout不够快，为了更快输入输出，直接关了同步流，一切就迎刃而解了，但是不要关了之后再两种输入输出混用</p>
<h3 id="没有提到的O2加速"><a href="#没有提到的O2加速" class="headerlink" title="没有提到的O2加速"></a>没有提到的O2加速</h3><p>这个不到万不得已我不用，O加速是分为各种类型的，通常使用的是O2加速</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(2)</span></span><br></pre></td></tr></table></figure>

<p>可以这么理解，你的代码为了写着简单，就啥也不管了，最后跑项目的时候都要通过各种方法优化之后执行。但是随着社会内卷越来越厉害，出题人也在不断内卷，出题人开始用坑人的时间卡算法，那种时候就要对他使用O2吧！</p>
<p>其实O加速其实很多，下文列出所有的加速，感兴趣可以看看知乎的回答，其他地方不是很好搜到有关内容</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(2)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(3)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;Ofast&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;inline&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fgcse&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fgcse-lm&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fipa-sra&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-ftree-pre&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-ftree-vrp&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fpeephole2&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-ffast-math&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fsched-spec&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;unroll-loops&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-falign-jumps&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-falign-loops&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-falign-labels&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fdevirtualize&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fcaller-saves&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fcrossjumping&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fthread-jumps&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-funroll-loops&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fwhole-program&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-freorder-blocks&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fschedule-insns&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;inline-functions&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-ftree-tail-merge&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fschedule-insns2&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fstrict-aliasing&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fstrict-overflow&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-falign-functions&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fcse-skip-blocks&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fcse-follow-jumps&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fsched-interblock&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fpartial-inlining&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;no-stack-protector&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-freorder-functions&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-findirect-inlining&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fhoist-adjacent-loads&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-frerun-cse-after-loop&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;inline-small-functions&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-finline-small-functions&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-ftree-switch-conversion&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-foptimize-sibling-calls&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fexpensive-optimizations&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-funsafe-loop-optimizations&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;inline-functions-called-once&quot;</span>)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> GCC optimize(<span class="meta-string">&quot;-fdelete-null-pointer-checks&quot;</span>)</span></span><br></pre></td></tr></table></figure>

<h3 id="cin-tie-0"><a href="#cin-tie-0" class="headerlink" title="cin.tie(0)"></a>cin.tie(0)</h3><p>解除cin和cout的绑定，进一步加速，但是我之前有一次加上之后WA了，就不敢用了www</p>
<p><strong>后续内容发下期</strong></p>
<hr>
<p><em>我是ALgarth，如果有缘，我们下次再见。</em></p>
<p><em>图片来自网络，侵删。</em></p>
<p><em>本人拙笔草见，如果内容有误，请及时联系修改</em></p>

            </div>
            
                <div class="kratos-copyright text-center clearfix">
                    <h5>本作品采用 <a rel="license nofollow" target="_blank" href="http://creativecommons.org/licenses/by-sa/4.0/">知识共享署名-相同方式共享 4.0 国际许可协议</a> 进行许可</h5>
                </div>
            
            <footer class="kratos-entry-footer clearfix">
                
                    <div class="post-like-donate text-center clearfix" id="post-like-donate">
                    
                        <a class="donate" href="javascript:;"><i class="fa fa-bitcoin"></i> 打赏</a>
                    
                    
                        <a class="share" href="javascript:;"><i class="fa fa-share-alt"></i> 分享</a>
                        <div class="share-wrap" style="display: none;">
    <div class="share-group">
        <a href="javascript:;" class="share-plain qq" onclick="share('qq');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-qq"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain qzone" onclick="share('qzone');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-star"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain weixin pop style-plain" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-weixin"></i>
            </div>
            <div class="share-int">
                <div class="qrcode" id="wechat-qr"></div>
                <p>打开微信“扫一扫”，打开网页后点击屏幕右上角分享按钮</p>
            </div>
        </a>
        <a href="javascript:;" class="share-plain weibo" onclick="share('weibo');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-weibo"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain facebook style-plain" onclick="share('facebook');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-facebook"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain twitter style-plain" onclick="share('twitter');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-twitter"></i>
            </div>
        </a>
    </div>
    <script type="text/javascript">
        $(()=>{
            new QRCode("wechat-qr", {
                text: "http://algarth.github.io/2020/10/11/C-primary/",
                width: 150,
                height: 150,
                correctLevel : QRCode.CorrectLevel.H
            });
        });
        function share(dest) {
            const qqBase        = "https://connect.qq.com/widget/shareqq/index.html?";
            const weiboBase     = "https://service.weibo.com/share/share.php?";
            const qzoneBase     = "https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?";
            const facebookBase  = "https://www.facebook.com/sharer/sharer.php?";
            const twitterBase   = "https://twitter.com/intent/tweet?";
            const hostUrl       = "http://algarth.github.io/2020/10/11/C-primary/";
            const title         = "「C++ primary（上部）」";
            const excerpt       = `本篇博客为的是复习一遍C++的基础知识，方便从C语言更快的转型为C++语言
本文只是快速的提供模板和粗略的将部分代码一笔带过
前言中当然要感谢柳婼姐和CSDN的c++相关资料，
那么，我们进入正题：
C语言向C++的进阶本文打算按照以...`;
            let _URL;
            switch (dest) {
                case "qq"       : _URL = qqBase+"url="+hostUrl+"&title="+title+"&desc=&summary="+excerpt+"&site=cxpy";     break;
                case "weibo"    : _URL = weiboBase+"url="+hostUrl+"&title="+title+excerpt;                                 break;
                case "qzone"    : _URL = qzoneBase+"url="+hostUrl+"&title="+title+"&desc=&summary="+excerpt+"&site=cxpy";  break;
                case "facebook" : _URL = facebookBase+"u="+hostUrl;                                                        break;
                case "twitter"  : _URL = twitterBase+"text="+title+excerpt+"&url="+hostUrl;                                break;
            }
            window.open(_URL);
        };
    </script>
</div>
                    
                    </div>
                
                <div class="footer-tag clearfix">
                    <div class="pull-left">
                    <i class="fa fa-tags"></i>
                        <a class="tag-none-link" href="/tags/c-%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E4%B8%8D%E5%85%A5%E9%97%A8/" rel="tag">c++从入门到不入门</a>
                    </div>
                    <div class="pull-date">
                    <span>最后编辑：2020-10-31</span>
                    </div>
                </div>
            </footer>
        </div>
        
            <nav class="navigation post-navigation clearfix" role="navigation">
                
                <div class="nav-previous clearfix">
                    <a title=" 必读前言（持续更新）" href="/2020/10/10/preface/">&lt; 上一篇</a>
                </div>
                
                
                <div class="nav-next clearfix">
                    <a title=" c++primary（下部）" href="/2020/10/11/c-primary-1/">下一篇 &gt;</a>
                </div>
                
            </nav>
        
        
    </article>
</section>
        </div>
                
            <section id="kratos-widget-area" class="col-md-4 hidden-xs hidden-sm">
                
                    <aside id="krw-about" class="widget widget-kratos-about clearfix">
    
    <div class="photo-background"></div>
    <div class="photo-wrapper clearfix">
        <div class="photo-wrapper-tip text-center">
            <img class="about-photo" src="/images/avatar.webp" />
        </div>
    </div>
    <div class="textwidget">
        
            <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#C%E8%AF%AD%E8%A8%80%E5%90%91C-%E7%9A%84%E8%BF%9B%E9%98%B6"><span class="toc-number">1.</span> <span class="toc-text">C语言向C++的进阶</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80-C-%E8%AF%AD%E8%A8%80%E7%9A%84%E4%BC%98%E5%8A%BF"><span class="toc-number">1.1.</span> <span class="toc-text">一. C++语言的优势</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C-%E5%88%9D%E6%AD%A5%E7%9A%84C-%E8%AF%AD%E6%B3%95%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.2.</span> <span class="toc-text">二. 初步的C++语法介绍</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#iostream"><span class="toc-number">1.2.1.</span> <span class="toc-text">iostream</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#namespace"><span class="toc-number">1.2.2.</span> <span class="toc-text">namespace</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cin%EF%BC%8Ccout"><span class="toc-number">1.2.3.</span> <span class="toc-text">cin，cout</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#endl"><span class="toc-number">1.2.4.</span> <span class="toc-text">endl</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89-%E6%9D%BF%E5%AD%90%E7%9A%84%E6%8F%90%E5%87%BA"><span class="toc-number">1.3.</span> <span class="toc-text">三. 板子的提出</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#bits-stdc"><span class="toc-number">1.3.1.</span> <span class="toc-text">bits&#x2F;stdc++</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#define"><span class="toc-number">1.3.2.</span> <span class="toc-text">define</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ios-sync-with-stdio-0"><span class="toc-number">1.3.3.</span> <span class="toc-text">ios::sync_with_stdio(0)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B2%A1%E6%9C%89%E6%8F%90%E5%88%B0%E7%9A%84O2%E5%8A%A0%E9%80%9F"><span class="toc-number">1.3.4.</span> <span class="toc-text">没有提到的O2加速</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cin-tie-0"><span class="toc-number">1.3.5.</span> <span class="toc-text">cin.tie(0)</span></a></li></ol></li></ol></li></ol>
        
    </div>
</aside>
                
                    <!-- Moved to about.ejs -->
                
                    

                
                    
  <aside id="krw-tags" class="widget widget-kratos-tags clearfix">
    <h4 class="widget-title"><i class="fa fa-tags"></i>标签聚合</h4>
      <div class="tag-clouds">
        <a href="/tags/OS/" style="font-size: 0.6em;">OS</a> <a href="/tags/c-%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E4%B8%8D%E5%85%A5%E9%97%A8/" style="font-size: 0.7em;">c++从入门到不入门</a> <a href="/tags/priority-queue/" style="font-size: 0.6em;">priority_queue</a> <a href="/tags/projectpool/" style="font-size: 0.6em;">projectpool</a> <a href="/tags/tmp/" style="font-size: 0.6em;">tmp</a> <a href="/tags/trailer/" style="font-size: 0.7em;">trailer</a> <a href="/tags/update/" style="font-size: 0.6em;">update</a> <a href="/tags/%E5%89%8D%E8%A8%80/" style="font-size: 0.6em;">前言</a> <a href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%84%E6%88%90%E5%8E%9F%E7%90%86/" style="font-size: 0.8em;">计算机组成原理</a> <a href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%84%E6%88%90%E5%8E%9F%E7%90%86%E6%B1%87%E6%80%BB/" style="font-size: 0.6em;">计算机组成原理汇总</a> <a href="/tags/%E8%AE%A1%E7%BD%91/" style="font-size: 0.6em;">计网</a>
      </div>
  </aside>

                
                    
  <aside id="krw-posts" class="widget widget-kratos-poststab">
  <h4 class="widget-title"><i class="fa fa-file"></i>最新文章</h4>
  <div class="tab-content">
      <ul class="list-group">
        
        
          
          
            <a class="list-group-item" href="/2021/12/23/tmp/"><i class="fa  fa-book"></i> 小范围开源期末材料</a>
            
          
        
          
          
            <a class="list-group-item" href="/2021/10/30/OS/"><i class="fa  fa-book"></i> OS第一章</a>
            
          
        
          
          
            <a class="list-group-item" href="/2021/10/23/cnet/"><i class="fa  fa-book"></i> 计网第一章</a>
            
          
        
          
          
        
          
          
            <a class="list-group-item" href="/2021/10/19/projectpool/"><i class="fa  fa-book"></i> 计划进程池设定</a>
            
          
        
          
          
        
          
          
            <a class="list-group-item" href="/2020/12/31/organization-ex/"><i class="fa  fa-book"></i> 计算机组成原理汇总篇</a>
            
          
        
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
      </ul>
  </div>
  </aside>

                
            </section>
        
        </div>
    </div>
</div>
<footer>
    <div id="footer">
        <div class="kr-tool text-center">
            <div class="tool">
                
                    <div class="box search-box">
                        <a href="/search/">
                            <span class="fa fa-search"></span>
                        </a>
                    </div>
                
                
                    <div class="box theme-box" id="darkmode-switch">
                        <span class="fa fa-adjust"></span>
                    </div>
                
                
            </div>
            <div class="box gotop-box">
                <span class="fa fa-chevron-up"></span>
            </div>
        </div>
        <div class="container">
            <div class="row">
                <div class="col-md-6 col-md-offset-3 footer-list text-center">
                    <ul class="kratos-social-icons">
                        
                        <li><a href="mailto:algarth@163.com"><i class="fa fa-envelope"></i></a></li>
                        
                        
                        
                        
                        
                        <li><a target="_blank" rel="nofollow" href="https://github.com/ALgarth"><i class="fa fa-github"></i></a></li>
                        
                    </ul>
                    <ul class="kratos-copyright">
                        <div>
                            <li>&copy; 2022 ALgarth 版权所有.</li>
                            <li>本站已运行<span id="span_dt">Loading...</span></li>
                        </div>
                        <div>
                            <li>Theme <a href="https://github.com/Candinya/Kratos-Rebirth" target="_blank">Kratos:Rebirth</a></li>
                            <li>Made with&nbsp;<i class="fa fa-heart throb" style="color:#d43f57"></i>&nbsp;by <a href="https://candinya.com" target="_blank" rel="nofollow">Candinya</a>.</li>
                        </div>
                        <div>
                            <li>Powered by <a href="https://hexo.io" target="_blank" rel="nofollow">Hexo</a></li>
                            <li>Hosted on <a href="https://github.io" target="_blank">Github Pages</a></li>
                        </div>
                        <div>
                            
                            
                        </div>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</footer>
</div>
</div>

        <script defer src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.4/dist/js/bootstrap.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.js"></script>
<script>const notMobile = (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)));</script>

    <div>
        <canvas id="snow"></canvas>
        <script async type="text/javascript" src="/js/snow.min.js"></script>
    </div>

<script async src="/js/candy.min.js"></script>


    <script defer src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

<script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js"></script>
<script defer src="/js/kratosr.min.js"></script>
<script defer src="/js/pjax.min.js"></script>

    <script defer src="https://cdn.jsdelivr.net/npm/layui-src@2.5.5/dist/layui.all.js"></script>


    <script defer src="/js/kr-dark.min.js"></script>


    </body>
</html>